<?php
require_once(dirname(__FILE__)."/../../../include/common.inc.php");
global $dsql;

$weixin = $dsql->GetOne("select * from wx_info where id=1");
$AppID = $weixin['appid'];
$AppSecret = $weixin['appsecret'];
$callback  =  $weixin['redirect_url'];//回调地址
$created_at = date("Y-m-d H:i:s");
//微信登录
$state  = md5(uniqid(rand(), TRUE));
$res = $dsql->ExecuteNoneQuery("INSERT INTO wx_state (`state`,`created_at`) VALUES ('$state','$created_at')");
if(!$res){
    ShowMsg('参数生成错误，及时联系程序员小锅锅~~~', 'index.php',0,8);
}
//-------生成唯一随机串防CSRF攻击

$_SESSION["wx_state"]    =   $state; //存到SESSION
$callback = urlencode($callback);
$wxurl = "https://open.weixin.qq.com/connect/qrconnect?appid=".$AppID."&redirect_uri={$callback}&response_type=code&scope=snsapi_login&state={$state}#wechat_redirect";
header("Location: $wxurl");